<template>
  <div class="operation-container">
    <el-row>
      <div class="left">
        <el-card>
          <el-tree
            :expand-on-click-node="false"
            node-key="id"
            :data="data"
            :default-expanded-keys="[2, 3]"
            :default-checked-keys="[5]"
            :props="defaultProps"
            @node-click="treeNodeClick"
          />
        </el-card>
      </div>
    </el-row>
    <el-row class="right">
      <div class="card-right">
        <el-card>
          <div slot="header" class="card-header">
            <span>机构信息</span>
            <div>
              <el-button
                v-show="!editParallel"
                size="small"
                type="success"
                class="buttonStyle"
                @click="editClick"
              >编辑</el-button>
              <el-button
                v-show="editParallel"
                size="small"
                type="success"
                class="buttonStyle"
                @click="saveClick"
              >保存</el-button>
              <el-button
                v-show="editParallel"
                size="small"
                type="success"
                style="width: 80px; height: 30px"
                plain
                @click="cancelClick"
              >取消</el-button>
            </div>
          </div>
          <div class="card-footer">
            <el-row class="footer-top">
              <span>地区关键词：</span>
              <el-input
                v-model="value"
                class="inputStyle"
                clearable
                placeholder="请输入地区关键词"
              />
            </el-row>
            <el-row class="footer-bottom" style="width: 100%">
              <div v-show="editParallel">
                <el-button
                  v-show="!drawbut"
                  type="success"
                  class="buttonStyle"
                  size="small"
                  @click="drawClick"
                >开始绘制</el-button>
                <el-button
                  v-show="drawbut"
                  type="success"
                  class="buttonStyle"
                  size="small"
                  style="margin: 0"
                  @click="finishClick"
                >完成绘制</el-button>
                <el-button
                  v-show="drawbut"
                  type="info"
                  plain
                  class="buttonStyle"
                  size="small"
                  @click="deleteClick"
                >删除围栏</el-button>
              </div>
              <el-row class="footer-bottom">
                <div v-show="editParallel" class="header-box">
                  <img src="@/assets/warn.png" alt="" class="warnImg">
                  <span
                    class="warningText"
                  >点击或拖动鼠标绘制电子围栏，右击鼠标结束图形绘制，图形不可有交叉点。完成绘制后，点击提交按钮保存。仅支持绘制单个电子围栏区域</span>
                </div>
                <div ref="allmap" class="footer-box">
                  <gaode-map />
                </div>
              </el-row>
            </el-row>
          </div>
        </el-card>
      </div>
    </el-row>
  </div>
</template>
<script>
import GaodeMap from '@/components/MapContainer/index.vue'
import {
  // getOrgDetailAPI,
  getOrgTreeAPI
  // getScopeEmployeeAPI
  // getAreaAPI
} from '@/api/data'
export default {
  components: {
    GaodeMap
  },
  data() {
    return {
      data: [
        {
          id: 1,
          label: '一级 1',
          children: [
            {
              id: 4,
              label: '二级 1-1',
              children: [
                {
                  id: 9,
                  label: '三级 1-1-1'
                },
                {
                  id: 10,
                  label: '三级 1-1-2'
                }
              ]
            }
          ]
        },
        {
          id: 2,
          label: '一级 2',
          children: [
            {
              id: 5,
              label: '二级 2-1'
            },
            {
              id: 6,
              label: '二级 2-2'
            }
          ]
        },
        {
          id: 3,
          label: '一级 3',
          children: [
            {
              id: 7,
              label: '二级 3-1'
            },
            {
              id: 8,
              label: '二级 3-2'
            }
          ]
        }
      ],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      editParallel: false,
      drawbut: false,
      value: '',
      // 地图
      center: {
        lng: 0,
        lat: 0
      }
    }
  },
  created() {
    this.treeData()
  },
  mounted() {
    this.map()
  },
  methods: {
    // 地图
    map() {
    },
    // 机构树点击事件
    treeNodeClick(key, node, tree) {
      // clearTimeout(this.timer)
      // this.timer = setTimeout(() => {
      //   getOrgDetailAPI(key.id).then(({ data }) => {
      //     const formData = data.data
      //     this.form = formData
      //   })
      //   getScopeEmployeeAPI(this.page, this.pageSize, key.id).then(
      //     ({ data }) => {
      //       const courierList = data.data
      //       this.total = +courierList.counts
      //       this.pages = +courierList.pages
      //       this.tableData = courierList.items
      //     }
      // )
      // }, 500)
    },
    // 机构树
    async treeData() {
      const result = await getOrgTreeAPI()
      this.data = JSON.parse(result.data.data)
    },
    // 绘制按钮
    drawClick() {
      this.drawbut = true
    },
    finishClick() {
      this.drawbut = false
    },
    deleteClick() {
      this.drawbut = false
    },
    // 头按钮
    editClick() {
      this.editParallel = true
    },
    saveClick() {
      this.editParallel = false
    },
    cancelClick() {
      this.editParallel = false
    }
  }
}
</script>

<style scoped lang="scss">
.operation-container {
  display: flex;
  padding: 10px;
  height: 100%;
  .left {
    padding: 0 10px;
    width: 208px;
    height: 100%;

    .left-card {
      height: 100%;
    }
    ::v-deep .el-card__body {
      height: 100%;
      padding: 0;
      padding-top: 9px;
      padding-left: 5px;
    }

    ::v-deep .el-card {
      height: 100%;
    }
  }

  .right {
    padding: 0 10px;
    flex-grow: 1;
    height: 100%;
    ::v-deep .el-card__header {
      padding: 10px 20px;
      background-color: #f8faff;
      font-size: 14px;
      font-weight: bold;
    }
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .buttonStyle {
        width: 80px;
        height: 30px;
        background-color: #189450;
        border-color: #189450;
      }
    }
    .card-footer {
      display: flex;
      align-items: flex-start;
      font-size: 13px;
      flex-direction: column;
      .footer-top {
        margin-bottom: 20px;
      }
      .inputStyle {
        width: 200px;
      }
    }

    .header-box {
      display: flex;
      align-items: center;
      justify-content: start;
      height: 30px;
      width: 100%;
      padding: 0 7px;
      margin-top: 10px;
      margin-bottom: 10px;
      background: rgb(255, 245, 231);
      .warnImg {
        width: 12px;
        height: 12px;
        font-size: 12px;
        margin-right: 10px;
        vertical-align: middle;
      }
      .warningText {
        font-size: 12px;
        color: rgb(198, 126, 18);
        vertical-align: middle;
      }
    }
    .footer-box {
      border: 2px solid #189450;
      width: 100%;
      height: 500px;
      box-sizing: border-box;

      .map {
        width: 100%;
        height: 100%;
      }
    }
  }
}

::v-deep .el-tree-node__content {
  height: 35px;
  background-color: transparent;

  & > .el-tree-node__label {
    font-size: 14px;
    &:hover {
      background-color: #f5f7fa;
      font-weight: 900;
      color: #189450;
    }
  }
}

::v-deep .el-tree-node__content {
  & > .el-tree-node__children {
    &
      > .el-tree-node
      > .el-tree-node__children
      > .el-tree-node
      > .el-tree-node__content
      > .el-tree-node__label {
      color: #818693;
      font-size: 12px;
      &:hover {
        background-color: #f5f7fa;
        font-weight: 900;
        color: #189450;
      }
    }
  }
}
</style>
